<?php

namespace App\Admin\Controllers;

use App\Admin\Forms\Setting;
use App\Schools;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;
use Illuminate\Http\Request;

class SchoolController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '学校页';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Schools());

        // $grid->column('id', __('Id'));
        $grid->column('name', __('学校名称'));
        $grid->column('logo', __('Logo'))->image('',30,30);
        // $grid->column('banner', __('Banner'));
        $grid->column('capacity', __('存储容量'));
        $grid->column('status', __('状态'))->using(['1' => '启用', '0' => '禁用']);
        $grid->column('created_at', __('创建时间'));
        $grid->column('updated_at', __('修改时间'));
        $grid->enableHotKeys();
        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(Schools::findOrFail($id));

        // $show->field('id', __('Id'));
        $show->field('name', __('学校名称'));
        $show->field('logo', __('Logo'))->image();
        $show->field('banner', __('轮播图'))->carousel();
        $show->field('capacity', __('存储容量'));
        $show->field('status', __('状态'));
        $show->field('created_at', __('创建时间'));
        $show->field('updated_at', __('修改时间'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Schools());

        $form->text('name', __('学校名称'));
        $form->image('logo', __('Logo'))->removable()->downloadable();
        $form->multipleImage('banner', __('轮播图'))->removable()->sortable();
        // $form->multipleFile('banner', __('轮播图'))->removable();
        $form->number('capacity', __('存储容量'));
        $form->switch('status', __('状态'))->default(1);

        return $form;
    }

    public function getSchools(Request $request){
        $schools = Schools::get();
        
        $schools = $schools->reject(function($fight){
            $fight->text = $fight->name;
        });

        return $schools;

    }

    public function studyApp(){
        dd(get_class(app('auth')));
    }

    
}
